package service;

import cn.bugstack.domain.req.ShopCartReq;
import cn.bugstack.domain.res.PayOrderRes;
import cn.bugstack.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

@Slf4j
@SpringBootTest(classes = cn.bugstack.Application.class) // 确保使用正确的Spring Boot应用类
public class OrderServiceTest {

    @Resource
    private IOrderService orderService;

    // 测试创建订单
    @Test
    void createOrderTest() {
        try {
            // 模拟购物车请求
            ShopCartReq shopCartReq = new ShopCartReq();
            shopCartReq.setUserId("123456");
            shopCartReq.setProductId("654321");

            // 调用创建订单方法
            PayOrderRes payOrderRes = orderService.createOrder(shopCartReq);

            // 输出结果
            log.info("创建订单成功，订单ID: {}, 支付链接: {}", payOrderRes.getOrderId(), payOrderRes.getPayUrl());
        } catch (Exception e) {
            log.error("创建订单失败", e);
        }
    }
}
